package com.sun.tv;

import java.util.ArrayList;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

public class SDKData {
	
	private static final String FORM_URL = "http://cast.ra.imocha.com/p/?"; // 发布服务器
	private static final String PUBLIC_TEST_URL = "http://qr.hdtmobile.com/p/?"; // 测试服务器
	private static final String SUN_TEST_URL = "http://labs.ra.icast.cn/imocha/ads/?"; // SUN服务器
	
	private boolean configOK = true;
	
	
	public String getServerUrl(int serverId){
		if(serverId == 0){
			return FORM_URL;
		}else if(serverId == 0){
			return PUBLIC_TEST_URL;
		}else {
			return SUN_TEST_URL;
		}
	}
	
	private StringBuffer errorMessage = new StringBuffer();
		// 检查用户添加权限
		public boolean checkPermisions(Context context) {
			try {
				PackageManager pm = context.getPackageManager();
				PackageInfo pi = pm
						.getPackageInfo(context.getPackageName(), 0);
				// 得到自己的包名
				PackageInfo pkgInfo = pm.getPackageInfo(pi.packageName,
						PackageManager.GET_PERMISSIONS);// 通过包名，返回包信息
				String sharedPkgList[] = pkgInfo.requestedPermissions;// 得到权限列表
				ArrayList<String> permisions = new ArrayList<String>();
				for (int i = 0; i < sharedPkgList.length; i++) {
					permisions.add(sharedPkgList[i]);
				}
				ArrayList<String> list = ImochaPermisions.checkPermisions(permisions);
				if (list != null && list.size() > 0) {
					configOK = false;
					
					errorMessage.append("请添加以下权限：\n");
					for (String string : list) {
						errorMessage.append(string + "\n");
					}
				}
			} catch (NameNotFoundException e) {
				Log.e("##ddd", "Could'nt retrieve permissions for package" + e);

			}
			return configOK;

		}
}
